﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.TcCommands.TcEndModeling.CApTcEndModelingProcessValidator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System.Collections.ObjectModel;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.TcCommands.TcEndModeling;

internal class CApTcEndModelingProcessValidator : ITxValidator
{
  private ITxTypeFilter _filter;
  private string _invalidObjMessage;
  private string _missingObjMessage;

  public ITxObject GetObject(string text)
  {
    ITxObject itxObject1 = (ITxObject) null;
    foreach (ITxObject itxObject2 in (Collection<ITxObject>) TxApplication.ActiveDocument.GetObjectsByName(text))
    {
      if (this.IsValidObject(itxObject2, out string _))
        itxObject1 = itxObject2;
    }
    return itxObject1;
  }

  public string GetText(ITxObject obj)
  {
    string text = string.Empty;
    if (obj != null)
      text = obj.Name;
    return text;
  }

  public bool IsValidObject(ITxObject obj, out string errorMessage)
  {
    bool flag = this._filter.DoesPassFilter(obj) && obj.CanBeModified;
    errorMessage = (string) null;
    if (!flag)
      errorMessage = this._invalidObjMessage;
    return flag;
  }

  public bool IsValidText(string text, out string errorMessage)
  {
    errorMessage = (string) null;
    bool flag = false;
    if (text == "")
      errorMessage = this._missingObjMessage;
    else if (this.GetObject(text) != null)
      flag = true;
    else
      errorMessage = this._invalidObjMessage;
    return flag;
  }

  public CApTcEndModelingProcessValidator(
    ITxTypeFilter filter,
    string invalidObjMessage,
    string missingObjMessage)
  {
    this._filter = filter;
    this._invalidObjMessage = invalidObjMessage;
    this._missingObjMessage = missingObjMessage;
  }

  public CApTcEndModelingProcessValidator(ITxTypeFilter filter)
  {
    this._filter = filter;
    this._invalidObjMessage = StringTable.TEM_INVALID_OBJECT;
    this._missingObjMessage = StringTable.TEM_MISSING_OBJECT;
  }
}
